package cmd

import (
	"app/config"
	"app/internal/bootstrap"
	"context"
	"github.com/spf13/cobra"
	"log"
)

func init() {
	rootCmd.AddCommand(queueCmd) //队列
}

var queueCmd = &cobra.Command{
	Use:   "queue",
	Short: "start queue work",
	Long:  `app queue -c etc/config.yml`,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		//加载配置
		return config.LoadFromFile(configYml)
	},
	Run: func(cmd *cobra.Command, args []string) {
		//启动队列
		log.Printf("【%s】服务启动中", cmd.Name())
		//注册队列驱动
		bootstrap.RegisterQueueDrivers()
		//启动
		bootstrap.QueueListen(context.Background())

		waitForShutdown()
		
		log.Printf("【%s】服务已经关闭", cmd.Name())
	},
	PostRunE: func(cmd *cobra.Command, args []string) error {
		return nil
	},
}
